package com.infoservice.dms.chana.actions;

import java.util.List;
import java.util.Map;
import java.io.Serializable;
import java.util.HashMap;
import org.apache.log4j.Logger;
import com.infoservice.dms.chana.dao.CommonDao;
import com.infoservice.dms.chana.dao.DeCommonDao;
import com.infoservice.dms.chana.dao.DeVehicleShippingDao;
import com.infoservice.dms.chana.service.DeUtility;
import com.infoservice.dms.chana.vo.VehicleShippingVO;
import com.infoservice.po3.core.util.ContextUtil;

/**
 * @Title: DeVehicleShipping.java
 *
 * @Description:订单发车记录下发
 *
 * @Copyright: Copyright (c) 2010
 *
 * @Company: www.infoservice.com.cn
 * @Date: 2010-7-26
 *
 * @author lishuai 
 * @mail   lishuai103@yahoo.cn	
 * @version 1.0
 * @remark 
 */
public class OSB21 extends AbstractSendTask {
	private Logger logger = Logger.getLogger(OSB21.class);
	public DeVehicleShippingDao dao = DeVehicleShippingDao.getInstance();
	private DeCommonDao deCommonDao = DeCommonDao.getInstance();
	private CommonDao commonDao = CommonDao.getInstance(); 
	public String handleExecute() {
		logger.info("====订单发车记录下发开始====");
		DeUtility de = new DeUtility();
		try {
			int count = 0;//记录发送成功的记录条数
			List<VehicleShippingVO> list = dao.getDeVehicleShipping();
			if (list.size() > 0) {
				for (VehicleShippingVO vo : list) {
					try {
						HashMap<String, Serializable> body = new HashMap<String, Serializable>();
						body.put("1", vo);
						Map<String, Object> map = deCommonDao.getDmsDealerCode(vo.getEntityCode());
						de.sendAMsg("DRB21", map.get("DMS_CODE").toString(), body);
						count++;
						//更新接口状态为已下发
						commonDao.updateComplete("TT_VS_DLVRY_RPC", "DELIVERY_NO", vo.getShippingOrderNo());
					} catch (Exception e) {
						logger.error("订单发车记录下发失败", e);
					}
				}
			}
			logger.info("====订单发车记录下发结束====, 下发了" + count + "条记录");
		} catch(Exception e) {
			logger.error("订单发车记录下发失败", e);
		}
		return null;
	}
	
	public static void main(String[] args) {
		ContextUtil.loadConf();
		OSB21 o = new OSB21();
		o.execute();
	}
}
